﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CVSToExcel.Utils
{
   public class DbUtil
    {
       static SqlConnectionStringBuilder _conStr;
        internal static SqlConnectionStringBuilder ConnectionString
        {
            get
            {
                if (_conStr == null)
                {
                    ApplicationSettings settings = new ApplicationSettings();
                    _conStr = new SqlConnectionStringBuilder(settings.ConnectionString);
                }
                return _conStr;
            }
        }

        internal static InstallResult TestDatabaseConnection(SqlConnectionStringBuilder connectionString)
        {
            InstallResult result = new InstallResult();
            var con = new SqlConnection(connectionString.ConnectionString);
            try
            {
                con.Open();
                result.Success = true;
                return result;
            }
            catch (Exception ex)
            {
                result.Message = ex.ToString();
                result.Success = false;
                return result;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
